package com.slj.controller;

import com.slj.entity.Books;
import com.slj.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/books")
public class BookController {
    @Autowired
    private  BookService bookService;




    // 新增书籍
    @PostMapping
    public boolean addBook(@RequestBody Books book) {
        return bookService.addBook(book);
    }

    // 删除书籍
    @DeleteMapping("/{id}")
    public boolean deleteBook(@PathVariable Integer id) {
        return bookService.deleteBook(id);
    }

    // 更新书籍
    @PutMapping
    public boolean updateBook(@RequestBody Books book) {
        return bookService.updateBook(book);
    }

    // 根据ID查询
    @GetMapping("/{id}")
    public Books getBookById(@PathVariable Integer id) {
        return bookService.getBookById(id);
    }

    // 查询全部
    @GetMapping
    public List<Books> getAllBooks() {
        return bookService.getAllBooks();
    }

    // 按书名搜索
    @GetMapping("/search")
    public List<Books> searchBooks(@RequestParam String name) {
        return bookService.searchBooksByName(name);
    }
}